<?php
include_once("../controller/sala_controller_class.php");
include_once("../controller/funcionario_controller_class.php");

$predios = $_POST['predios'];

//$predios[0] = 1;
//$predios[1] = 2;
//$predios[2] = 3;

$objSala = new SalaController();

$listFunc = array();
foreach($predios as $predio){
    
    $listSala = $objSala->selecionarSalasPorPredio($predio);
    
    foreach($listSala as $sala){
        $objFunc = new FuncionarioController();
        $listFunc[] = $objFunc->selecionarPorSala($sala->getId());
    }
    
}
//echo "<pre>";
//var_dump($listFunc);
$retorno[0] = array('nome' => "");
$i = 0;

$objPredio = new PredioController();
$objCampus = new CampusController();

if(count($listFunc)>0){
    foreach($listFunc as $func){
        foreach($func->getTelefone() as $tel){

            $retorno[$i++] = array(
                'nome' => $func->getNome(),
                'numero' => $tel->getTelefone(),
                'predio' => $func->getSala()->getPredio()->getNome(),
                'campus' => $func->getSala()->getPredio()->getCampus()->getNome(),
                'sala' => $func->getSala()->getIdentificacao(),
            );
        }
    }
}

//echo "<pre>";
//var_dump($retorno);
//exit;

echo json_encode($retorno);